using System;
using System.Diagnostics;

using org.fourzoas.noise.module;

namespace org.fourzoas.noise.module {
  /// <summary>
  /// Noise module that outputs the absolute value of the output value from a source module.
  /// </summary>
  /// <remarks>
  /// <img src="file://C:/temp/noise/noise/doc/html/moduleabs.png"/>
  /// <para>
  /// This noise module requires one source module.
  /// </para>
  /// </remarks>
  public class Abs : ModifierModule {
    /// <summary>
    /// Default constructor.
    /// </summary>
    public Abs() : base(1) { }
    /// <summary>
    /// Number of source modules needed.
    /// </summary>
    /// <returns>1</returns>
    public override int GetSourceModuleCount() {
      return 1;
    }
    /// <summary>
    /// Gets the value at a given point.
    /// </summary>
    /// <param name="x"><em>x</em> coordinate</param>
    /// <param name="y"><em>y</em> coordinate</param>
    /// <param name="z"><em>z</em> coordinate</param>
    /// <returns>The value at the given point.</returns>
    public override double GetValue(double x, double y, double z) {
      Debug.Assert(m_sourceModule[0] != null);
      return Math.Abs(m_sourceModule[0].GetValue(x, y, z));
    }
  }
}